/* gm_start.js.php <?php
#   --------------------------------------------------------------
#   gm_start.js.php 2012-01-19 gm
#   Gambio GmbH
#   http://www.gambio.de
#   Copyright (c) 2012 Gambio GmbH
#   Released under the GNU General Public License
#   --------------------------------------------------------------
?>*/

<?php
if($_SESSION['style_edit_mode'] == 'edit') echo 'var gm_style_edit_mode_running = true;';
?>

var gmMegaFlyOver = null;
var gmLightBox = null;
<?php
if(gm_get_env_info('TEMPLATE_VERSION') < FIRST_GX2_TEMPLATE_VERSION)
{
?>
var gmProductImages = null;
var gmLiveSearch = null;
<?php
}
else
{
if(isset($_GET['page']) && $_GET['page'] == 'Index')
{
?>
var coo_button_sorting_change_handler = null;
<?php
}
}
?>
<?php
	if(gm_get_conf('GM_OPENSEARCH_BOX') == '1' || gm_get_conf('GM_OPENSEARCH_SEARCH') == '1') echo 'var gmOpenSearch = null;';
?>

<?php
if(gm_get_env_info('TEMPLATE_VERSION') >= FIRST_GX2_TEMPLATE_VERSION && isset($_GET['page']) && $_GET['page'] == 'Cart')
{
?>
// Handlers for order_details.html
var coo_button_cart_refresh_handler = null;
var coo_button_cart_delete_handler = null;
var coo_combi_status_check = null;
<?php
}
elseif(gm_get_env_info('TEMPLATE_VERSION') >= FIRST_GX2_TEMPLATE_VERSION && isset($_GET['page']) && $_GET['page'] == 'Wishlist')
{
?>
// Handlers for wish list
var coo_button_wish_list_to_cart_handler = null;
var coo_button_update_wish_list_handler = null;
var coo_button_delete_wish_list_handler = null;
<?php } ?>

var gm_scroller_height = <?php echo gm_get_conf('GM_SCROLLER_HEIGHT'); ?>;

<?php
if(gm_get_env_info('TEMPLATE_VERSION') >= FIRST_GX2_TEMPLATE_VERSION)
{
?>

<?php
if(isset($_GET['page']) && $_GET['page'] == 'ProductInfo')
{
?>
var coo_button_product_images_handler = null;
var coo_combi_status_check = null;
var coo_dropdowns_listener = null;
<?php } ?>

var coo_megadropdown_handler = null;
var coo_cart_dropdown_handler = null;
var coo_cart_control = null;

<?php } ?>

$(document).ready(function() {

	gmLightBox = new GMLightBox();

	<?php if(gm_get_conf('GM_SHOW_FLYOVER') == '1') {
		// TODO: option for slideshow in flyover
		if(true)
		{
			echo "var t_slideshow = true;\n";
		}
		else
		{
			echo "var t_slideshow = false;\n";
		}
	?>
	gmMegaFlyOver = new GMMegaFlyOver(t_slideshow);
	<?php } ?>

	<?php
	if(gm_get_env_info('TEMPLATE_VERSION') >= FIRST_GX2_TEMPLATE_VERSION)
	{
	?>
	coo_cart_control = new CartControl();
	<?php
	if(isset($_GET['page']) && $_GET['page'] == 'Cart')
	{
	?>
	// Handlers for order_details.html
	coo_button_cart_refresh_handler = new ButtonCartRefreshHandler();
	coo_button_cart_delete_handler = new ButtonCartDeleteHandler();
	coo_combi_status_check = new CombiStatusCheck();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'Wishlist')
	{
	?>
	// Handlers for wish list
	coo_button_wish_list_to_cart_handler = new ButtonWishListToCartHandler();
	coo_button_update_wish_list_handler = new ButtonUpdateWishListHandler();
	coo_button_delete_wish_list_handler = new ButtonDeleteWishListHandler();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'ProductInfo')
	{
	?>
	coo_combi_status_check = new CombiStatusCheck();
	coo_dropdowns_listener = new DropdownsListener();
	<?php } ?>

	$("a.button").bind({
		mousedown: function(){
			$(this).addClass("active");
		},
		mouseup: function(){
			$(this).removeClass("active");
		},
		mouseout: function(){
			$(this).removeClass("active");
		}
	});

	<?php
	if(gm_get_conf('CAT_MENU_TOP') == 'true')
	{
	?>
	coo_megadropdown_handler = new MegadropdownHandler();
	<?php
	}
	if(gm_get_conf('CAT_MENU_LEFT') == 'true')
	{
	?>
	coo_sumbmenu_handler = new SubmenuHandler();
	<?php
	}
	?>

	// Global Handler
	coo_top_navigation_handler = new TopNavigationHandler();
	coo_cart_dropdown_handler = new CartDropdownHandler();
	var coo_ie6_handler = new IE6Handler();
	var coo_action_submit_handler = new ActionSubmitHandler();
	var coo_reset_form_handler = new ResetFormHandler();
	var coo_input_enter_key_handler = new InputEnterKeyHandler();
	// PULLDOWN MENUS
	var coo_pull_down_link_handler = new PullDownLinkHandler();
	// CURRENCIES BOX
	var coo_button_currency_change_handler = new ButtonCurrencyChangeHandler();
	// OPENSEARCH
	var coo_button_open_search_handler = new ButtonOpenSearchHandler();

	<?php
	if(gm_get_conf('GM_QUICK_SEARCH') == 'true' || (isset($_GET['page']) && $_GET['page'] == 'Cart'))
	{
	?>
	var coo_input_default_value_handler = new InputDefaultValueHandler();
	<?php
	}
	if(isset($_GET['page']) && ($_GET['page'] == 'Account' || $_GET['page'] == 'Checkout'))
	{
	?>
	var coo_form_highlighter_handler = new FormHighlighterHandler();
	<?php
	}
	if(gm_get_conf('GM_QUICK_SEARCH') == 'true')
	{
	?>
	var coo_live_search_handler = new LiveSearchHandler();
	<?php
	}
	if(isset($_GET['page']) && $_GET['page'] == 'ProductInfo')
	{
	?>
	// Handler for standard.html
	coo_button_product_images_handler = new ButtonProductImagesHandler(<?php echo gm_get_conf('SHOW_GALLERY'); ?>, <?php echo gm_get_conf('SHOW_ZOOM'); ?>, 500);
	var coo_button_details_add_cart_handler = new ButtonDetailsAddCartHandler();
	<?php
	if(gm_get_conf('GM_SHOW_WISHLIST') == 'true')
	{
	?>
	var coo_button_details_add_wishlist_handler = new ButtonDetailsAddWishlistHandler();
	<?php
	}
	if(gm_get_conf('SHOW_BOOKMARKING') == 'true')
	{
	?>
	var coo_button_bookmark_handler = new ButtonBookmarkHandler();
	<?php
	}
	if(gm_get_conf('GM_TELL_A_FRIEND') == 'true')
	{
	?>
	var coo_button_tell_a_friend_handler = new ButtonTellAFriendHandler();
	<?php
	}
	}
	elseif(isset($_GET['page']) && ($_GET['page'] == 'Cat' || $_GET['page'] == 'Manufacturers' ))
	{
	?>
	// Handler for listing
	<?php
	$coo_cat_extender_component = MainFactory::create_object('JSCatExtenderComponent');
	$coo_cat_extender_component->set_data('GET', $_GET);

	if($coo_cat_extender_component->get_calculate_price() == true)
	{
	?>
	var coo_attributes_calculator_handler = new AttributesCalculatorHandler();
	<?php
	}
	?>
	var coo_action_add_to_cart_handler = new ActionAddToCartHandler();
	var coo_button_manufacturer_change_handler = new ButtonManufacturerChangeHandler();
	var coo_button_sorting_change_handler = new ButtonSortingChangeHandler();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'AccountHistory')
	{
	?>
	// Handler for account_history_info.html
	var coo_button_print_order_handler = new ButtonPrintOrderHandler();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'Checkout')
	{
	?>
	<?php
	if(gm_get_conf('GM_LIGHTBOX_CHECKOUT') == 'true')
	{
	?>
	//Handler for complete checkout
	var coo_button_close_lightbox = new ButtonCloseLightboxHandler();
	<?php
	}
	?>

	// Handler for checkout_success.html
	var coo_button_print_order_handler = new ButtonPrintOrderHandler();

	// Handler for checkout_paypal.html
	<?php
	if(MODULE_PAYMENT_PAYPALEXPRESS_STATUS == 'True')
	{
	?>
	var coo_button_paypal_express_handler = new ButtonPayPalExpressHandler();
	<?php
	}
	?>
	var coo_button_checkout_module_handler = new ButtonCheckoutModuleHandler();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'GVSend')
	{
	?>
	// Handler for gv_send.html
	var coo_button_gv_send_back_handler = new ButtonGVSendBackHandler();
	<?php
	}
	elseif(isset($_GET['page']) && $_GET['page'] == 'Index')
	{
	?>
	coo_button_sorting_change_handler = new ButtonSortingChangeHandler();
	<?php
	}
	}
	else
	{
	?>
	//IE6 hotfix work-around BOF
	var version=navigator.appVersion;
	if (version.indexOf ("MSIE 6")!=-1 && $(".column_content").length > 0)
	{
		var max_off = document.getElementById('column_content').offsetHeight;
		if(max_off < document.getElementById('column_left').offsetHeight) 	max_off = document.getElementById('column_left').offsetHeight;
		if(max_off < document.getElementById('column_right').offsetHeight) 	max_off = document.getElementById('column_right').offsetHeight;
		$('#column_content').css('height', max_off + 'px');
	}
	//IE6 hotfix work-around EOF

	gmProductImages = new GMProductImages();
	gmLiveSearch = new GMLiveSearch();

	<?php
	if(gm_get_conf('GM_OPENSEARCH_BOX') == '1' || gm_get_conf('GM_OPENSEARCH_SEARCH') == '1') echo 'gmOpenSearch = new GMAskOpensearch();';
	?>

<?php
	if($_SESSION['style_edit_mode'] != 'edit') 	{
?>
	if($("#menubox_cart_body").attr('id') == 'menubox_cart_body') {
		gm_link_box_cart('<?php echo xtc_href_link('shopping_cart.php'); ?>', '#menubox_cart_body');
	}
	if($("#cart_on_top").attr('id') == 'cart_on_top') {
		gm_link_box_cart('<?php echo xtc_href_link('shopping_cart.php'); ?>', '#cart_on_top');
	}
<?php
	}

	$cat_bg = '#E7E7E7';
	$get_cat_bg = xtc_db_query("SELECT sc.style_value
															FROM
																gm_css_style s,
																gm_css_style_content sc
															WHERE
																s.style_name = '#menubox_categories .categories'
																AND s.gm_css_style_id = sc.gm_css_style_id
																AND sc.style_attribute = 'background-color'
																LIMIT 1");
	if(xtc_db_num_rows($get_cat_bg) == 1){
		$row = xtc_db_fetch_array($get_cat_bg);
		$cat_bg = $row['style_value'];
	}
	?>
	$("#menubox_categories .categories").mouseover(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo gm_get_conf('GM_CAT_HOVER'); ?>'
			});
	});

	$("#menubox_categories .categories").mouseout(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo $cat_bg; ?>'
			});
	});

	<?php
	$top_bg = '#ffffff';
	$get_top_bg = xtc_db_query("SELECT sc.style_value
															FROM
																gm_css_style s,
																gm_css_style_content sc
															WHERE
																s.style_name = '#content_box_new_products_default_body .product_box'
																AND s.gm_css_style_id = sc.gm_css_style_id
																AND sc.style_attribute = 'background-color'
																LIMIT 1");
	if(xtc_db_num_rows($get_top_bg) == 1){
		$row = xtc_db_fetch_array($get_top_bg);
		$top_bg = $row['style_value'];
	}
	?>
	$("#main_content_container #content_box_new_products_default_body .product_box").mouseover(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo gm_get_conf('GM_STARTPAGE_HOVER'); ?>'
			});
	});

	$("#main_content_container #content_box_new_products_default_body .product_box").mouseout(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo $top_bg; ?>'
			});
	});

	<?php
	$specials_bg = '#ffffff';
	$get_specials_bg = xtc_db_query("SELECT sc.style_value
															FROM
																gm_css_style s,
																gm_css_style_content sc
															WHERE
																s.style_name = '#content_box_specials_body .product_box'
																AND s.gm_css_style_id = sc.gm_css_style_id
																AND sc.style_attribute = 'background-color'
																LIMIT 1");
	if(xtc_db_num_rows($get_specials_bg) == 1){
		$row = xtc_db_fetch_array($get_specials_bg);
		$specials_bg = $row['style_value'];
	}
	?>
	$("#main_content_container #content_box_specials_body .product_box").mouseover(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo gm_get_conf('GM_STARTPAGE_HOVER'); ?>'
			});
	});

	$("#main_content_container #content_box_specials_body .product_box").mouseout(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo $specials_bg; ?>'
			});
	});

	<?php
	$new_products_bg = '#ffffff';
	$get_new_products_bg = xtc_db_query("SELECT sc.style_value
															FROM
																gm_css_style s,
																gm_css_style_content sc
															WHERE
																s.style_name = '#content_box_new_products_main_body'
																AND s.gm_css_style_id = sc.gm_css_style_id
																AND sc.style_attribute = 'background-color'
																LIMIT 1");
	if(xtc_db_num_rows($get_new_products_bg) == 1){
		$row = xtc_db_fetch_array($get_new_products_bg);
		$new_products_bg = $row['style_value'];
	}
	?>
	$("#main_content_container #content_box_new_products_main_body .product_box").mouseover(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo gm_get_conf('GM_STARTPAGE_HOVER'); ?>'
			});
	});

	$("#main_content_container #content_box_new_products_main_body .product_box").mouseout(function(){
		$(this).css(
			{
				'background-color': 	'<?php echo $new_products_bg; ?>'
			});
	});
	<?php
	}
	?>

	<?php
	if(gm_get_conf('GM_STATUSBAR_ACTIVE') == 'true') echo 'gm_statusbar();';
	?>

	<?php
	if(isset($_GET['page']) && $_GET['page'] == 'Checkout')
	{
		?>
		//Handler for keep the session alive for complete checkout
		var coo_preserve_session = new PreserveSessionHandler(300000);
		<?php
	}
	?>
});
